package kr.totalcall.controls
{
	/**
	 * 작업 기록
	 * 2012. 6. 12. / 이규광 / 최초 작성.
	 */
	/**
	 * 내용.
	 * 숫자 입력 TextInput
	 * @productversion Flex 4.5
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 10.2
	 * @author 이규광.
	 */
	import spark.components.TextInput;
	import spark.events.TextOperationEvent;
	import spark.formatters.NumberFormatter;
	
	public class DatagridNumberTextInput extends TextInput
	{
		
		public static var numberFormatter:NumberFormatter = new NumberFormatter();
		
		/**
		 * 생성자
		 */
		public function DatagridNumberTextInput()
		{
			super();
			numberFormatter.useGrouping = true;
			numberFormatter.fractionalDigits = 0;
			
			text = "0";
			setStyle("textAlign", "right");
			
			addEventListener(TextOperationEvent.CHANGE, textChangeHandler);
		}
		
		
		/**
		 * 콤마를 붙여 포맷팅하고 커서를 맨 마지막으로 옮긴다.
		 */
		protected function textChangeHandler(event:TextOperationEvent):void{
			if( text == "-" )
			{
				return;
			}
			text = numberFormatter.format(text.slice(0, 12 + ( text.charAt() == "-" )).replace(/,/g, ""));
			selectRange(text.length, text.length);
		}
		
		
		override protected function partRemoved(partName:String, instance:Object):void{
			super.partRemoved(partName, instance);
			removeEventListener(TextOperationEvent.CHANGE, textChangeHandler);
		}
		
	}
}